using HKB.Common;
using HKB.Data.Dal;
using HKB.Data.Model;
using System;
using System.Collections.Generic;
using System.Data;
namespace HKB.Data.Bll
{
	public class UserCardRecordBll
	{
		private static UserCardRecordBll _instance = null;
		private readonly UserCardRecordDal dal = new UserCardRecordDal();
		public static UserCardRecordBll instance
		{
			get
			{
				if (UserCardRecordBll._instance == null)
				{
					UserCardRecordBll._instance = new UserCardRecordBll();
				}
				return UserCardRecordBll._instance;
			}
		}
		public bool Exists(long id)
		{
			return this.dal.Exists(id);
		}
		public long Add(UserCardRecordModel model)
		{
			return this.dal.Add(model);
		}
		public bool Update(UserCardRecordModel model)
		{
			return this.dal.Update(model);
		}
		public bool Delete(long id)
		{
			return this.dal.Delete(id);
		}
		public bool DeleteList(string idlist)
		{
			return this.dal.DeleteList(idlist);
		}
		public UserCardRecordModel GetModel(long id)
		{
			return this.dal.GetModel(id);
		}
		public UserCardRecordModel GetModelByCache(long id)
		{
			string cacheKey = "UserCardRecordModel_" + id;
			object obj = DataCache.GetCache(cacheKey);
			if (obj == null)
			{
				try
				{
					obj = this.dal.GetModel(id);
					if (obj != null)
					{
						int configInt = ConfigHelper.GetConfigInt("ModelCache");
						DataCache.SetCache(cacheKey, obj, System.DateTime.Now.AddMinutes((double)configInt), System.TimeSpan.Zero);
					}
				}
				catch
				{
				}
			}
			return (UserCardRecordModel)obj;
		}
		public DataSet GetList(string strWhere)
		{
			return this.dal.GetList(strWhere);
		}
		public DataSet GetList(int Top, string strWhere, string filedOrder)
		{
			return this.dal.GetList(Top, strWhere, filedOrder);
		}
		public System.Collections.Generic.List<UserCardRecordModel> GetModelList(string strWhere)
		{
			DataSet list = this.dal.GetList(strWhere);
			return this.DataTableToList(list.Tables[0]);
		}
		public System.Collections.Generic.List<UserCardRecordModel> DataTableToList(DataTable dt)
		{
			System.Collections.Generic.List<UserCardRecordModel> list = new System.Collections.Generic.List<UserCardRecordModel>();
			int count = dt.Rows.Count;
			if (count > 0)
			{
				for (int i = 0; i < count; i++)
				{
					UserCardRecordModel userCardRecordModel = new UserCardRecordModel();
					if (dt.Rows[i]["id"] != null && dt.Rows[i]["id"].ToString() != "")
					{
						userCardRecordModel.id = new long?(long.Parse(dt.Rows[i]["id"].ToString()));
					}
					if (dt.Rows[i]["UserID"] != null && dt.Rows[i]["UserID"].ToString() != "")
					{
						userCardRecordModel.UserID = new int?(int.Parse(dt.Rows[i]["UserID"].ToString()));
					}
					userCardRecordModel.CardType = dt.Rows[i]["CardType"].ToString();
					userCardRecordModel.CardNumber = dt.Rows[i]["CardNumber"].ToString();
					if (dt.Rows[i]["Amount"] != null && dt.Rows[i]["Amount"].ToString() != "")
					{
						userCardRecordModel.Amount = new decimal?(decimal.Parse(dt.Rows[i]["Amount"].ToString()));
					}
					if (dt.Rows[i]["UserTime"] != null && dt.Rows[i]["UserTime"].ToString() != "")
					{
						userCardRecordModel.UserTime = new System.DateTime?(System.DateTime.Parse(dt.Rows[i]["UserTime"].ToString()));
					}
					userCardRecordModel.Remark = dt.Rows[i]["Remark"].ToString();
					list.Add(userCardRecordModel);
				}
			}
			return list;
		}
		public DataSet GetAllList()
		{
			return this.GetList("");
		}
		public DataSet GetListRowid(int Top, string strWhere, string filedOrder, params string[] selectField)
		{
			return this.dal.GetListRowid(Top, strWhere, filedOrder, selectField);
		}
		public DataSet GetPagedList(int PageIndex, int PageSize, string strWhere, string Order)
		{
			return this.dal.GetPagedList(PageIndex, PageSize, strWhere, Order);
		}
		public DataSet PageOrderList(int PageSize, int PageIndex, string Orderfld, int OrderType, string strWhere)
		{
			return Conn.ExecProSpPageOrder("MBF_UserCardRecord", " ROW_NUMBER() OVER (ORDER BY id ASC) rowid,*", PageSize, PageIndex, Orderfld, OrderType, strWhere);
		}
		public long Add(UserCardRecordModel model, params Conn[] conn)
		{
			return this.dal.Add(model, conn);
		}
	}
}
